package com.utils.report;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.WorkbookFactory;


/*
 * 特殊打印实现基类
 *
 */
public class ExcelTsPrintByPOI {
	private OutputStream out;//输出流
	private String templatepath;//模版路径
	private ExcelTsPrint print;//特殊打印实现类

	public ExcelTsPrintByPOI() {
		
	}

	public ExcelTsPrintByPOI(OutputStream out, String templatepath,
			ExcelTsPrint print) {
		this.out = out;
		this.templatepath = templatepath;
		this.print = print;
	}

	public OutputStream tsPrint() throws InvalidFormatException, FileNotFoundException, IOException {
		File template = new File(this.templatepath);
		if(template==null || !template.exists()){
			throw new NullPointerException("模版不能为空！");
		}
		this.print.hssfWorkbook = WorkbookFactory.create(new FileInputStream(template));
		this.print.sheet0 = this.print.hssfWorkbook.getSheetAt(0);
		this.print.tsPrint(this.print.hssfWorkbook,this.print.sheet0);
        this.print.hssfWorkbook.write(this.out);
		return this.out;
	}

	public OutputStream getOut() {
		return out;
	}

	public void setOut(OutputStream out) {
		this.out = out;
	}

	public String getTemplatepath() {
		return templatepath;
	}

	public void setTemplatepath(String templatepath) {
		this.templatepath = templatepath;
	}

	public ExcelTsPrint getPrint() {
		return print;
	}

	public void setPrint(ExcelTsPrint print) {
		this.print = print;
	}
}
